home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0080_Marquee Panel For Delphi.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  14.3 KB  |  513 lines

  1. {
  2.   This component uses the VGA standard 8x16 font. No resources are used.
  3.  
  4.   properties description:
  5.  
  6.     property BackGround:     Background color of panel. Not visible if size is 1,
  7.                              because pixeldensity is too high.
  8.  
  9.     property BevelOuter:     as usual.
  10.     property BevelInner:     as usual.
  11.     property BevelWidth:     as usual.
  12.     property Characters:     How many Character are displayed in panel.
  13.                              Increasing this slows down the outputspeed.
  14.     property OffColor:       Color of Pixels not set in character.
  15.     property OnColor:        Color of Pixels set in character.
  16.     property OnComplete:     Fired if output of RunText completed.
  17.     property Running:        Flag if horizontal scrolling is active.
  18.     property RunText:        Outputstring.
  19.     property ScrollBy:       Number of pixels per horizontal scroll.
  20.     property ScrollInterval: Cycletime of horizontal scrolling.
  21.     property Size:           Size of output. If set to 1 character size is 8x16
  22.                              pixels. Increasing size decreases display contrast.
  23.  
  24.   Contact: Udo Juerss, 57078 Siegen, Germany, CompuServe [101364,526]
  25.  
  26.   Previously published by me: Luffing switch      (March  8. 1996)
  27.                               Scaleable LED light (March 10. 1996)
  28.  
  29.   If someone makes useful enhances or corrections to these components,
  30.   please send me an update!
  31.  
  32.   March 11. 1996
  33. }
  34.  
  35. unit
  36.   Marquee;
  37. {------------------------------------------------------------------------------}
  38.  
  39. interface
  40.  
  41. uses
  42.   WinTypes, WinProcs, Messages, Classes, Graphics, Controls, ExtCtrls;
  43. {------------------------------------------------------------------------------}
  44.  
  45. const
  46.   Dual: array[0..7] of Byte = (1,2,4,8,16,32,64,128);
  47. {------------------------------------------------------------------------------}
  48.  
  49. type
  50.   TMarquee = class(TGraphicControl)
  51.   private
  52.     Timer: TTimer;
  53.  
  54.     FBackGround: TColor;
  55.     FBevelOuter: TPanelBevel;
  56.     FBevelInner: TPanelBevel;
  57.     FBevelWidth: Byte;
  58.     FBkGnd: TColor;
  59.     FCharacters: Byte;
  60.     FScrollInterval: Word;
  61.     FOffColor: TColor;
  62.     FOnColor: TColor;
  63.     FOnComplete: TNotifyEvent;
  64.     FRunning: Boolean;
  65.     FRunText: string;
  66.     FSize: Byte;
  67.     FScrollBy: Byte;
  68.  
  69.     Border:Byte;
  70.     Index: Byte;
  71.     WorkString: string;
  72.     PixelPos: Byte;
  73.     CharOfs: Word;
  74.     TextLen: Byte;
  75.     XPos: Integer;
  76.     YPos: Integer;
  77.     procedure Draw;
  78.     procedure DrawText(Shift:Boolean);
  79.     procedure GetCharData(Character: Char);
  80.     procedure PutVerticalPixels(Horizontal: Byte);
  81.     procedure Setup;
  82.     procedure ShiftString;
  83.     procedure TimerShift(Sender: TObject);
  84.   protected
  85.     procedure DrawBevel(Rect: TRect);
  86.     procedure SetBackGround(Value: TColor);
  87.     procedure SetBevelOuter(Value: TPanelBevel);
  88.     procedure SetBevelInner(Value: TPanelBevel);
  89.     procedure SetBevelWidth(Value: Byte);
  90.     procedure SetCharacters(Value: Byte);
  91.     procedure SetScrollInterval(Value: Word);
  92.     procedure SetOffColor(Value: TColor);
  93.     procedure SetOnColor(Value: TColor);
  94.     procedure SetRunning(Value: Boolean);
  95.     procedure SetRunText(Value: string);
  96.     procedure SetSize(Value: Byte);
  97.     procedure SetScrollBy(Value: Byte);
  98.   public
  99.     constructor Create(AOwner: TComponent); override;
  100.     destructor Destroy; override;
  101.     procedure Clear;
  102.     procedure Paint; override;
  103.   published
  104.     property BackGround: TColor read FBackGround write SetBackGround default clBlack;
  105.     property BevelOuter: TPanelBevel read FBevelOuter write SetBevelOuter default bvRaised;
  106.     property BevelInner: TPanelBevel read FBevelInner write SetBevelInner default bvLowered;
  107.     property BevelWidth: Byte read FBevelWidth write SetBevelWidth default 2;
  108.     property Characters: Byte read FCharacters write SetCharacters default 7;
  109.     property ScrollInterval: Word read FScrollInterval write SetScrollInterval default 50;
  110.     property OffColor: TColor read FOffColor write SetOffColor default clGray;
  111.     property OnColor: TColor read FOnColor write SetOnColor default clLime;
  112.     property OnComplete: TNotifyEvent read FOnComplete write FOnComplete;
  113.     property Running: Boolean read FRunning write SetRunning default False;
  114.     property RunText: string read FRunText write SetRunText;
  115.     property ScrollBy: Byte read FScrollBy write SetScrollBy default 1;
  116.     property Size: Byte read FSize write SetSize default 2;
  117.   end;
  118. {------------------------------------------------------------------------------}
  119.  
  120. procedure GetFontOfs(CharSet: Byte; var FntOfs: Word);
  121. function SegC000: Word;
  122. procedure Register;
  123.  
  124. implementation
  125. {------------------------------------------------------------------------------}
  126.  
  127. var
  128.   CharArray: array[0..15] of Byte;
  129.   FontPtr: Pointer;
  130.   FontOfs: Word;
  131. {------------------------------------------------------------------------------}
  132.  
  133. procedure GetFontOfs(CharSet: Byte; var FntOfs: Word); assembler;
  134. asm
  135.            push  bp
  136.            mov   ax,1130h
  137.            mov   bh,CharSet
  138.            int   10h
  139.            mov   ax,bp
  140.            pop   bp
  141.            les   di,FntOfs
  142.            stosw
  143. end;
  144. {------------------------------------------------------------------------------}
  145.  
  146. function SegC000: Word; external 'KERNEL' Index 195;
  147. {------------------------------------------------------------------------------}
  148.  
  149. constructor TMarquee.Create(AOwner: TComponent);
  150. begin
  151.   inherited Create(AOwner);
  152.   Parent:=AOwner as TWinControl;
  153.   Canvas.Brush.Style:=bsSolid;
  154.   Timer:=nil;
  155.   FBackGround:=clBlack;
  156.   FBevelOuter:=bvRaised;
  157.   FBevelInner:=bvLowered;
  158.   FBevelWidth:=2;
  159.   FCharacters:=7;
  160.   FScrollInterval:=50;
  161.   FOffColor:=clGray;
  162.   FOnColor:=clLime;
  163.   FOnComplete:=nil;
  164.   FRunning:=False;
  165.   FRunText:='RunText ';
  166.   FSize:=2;
  167.   FScrollBy:=1;
  168.  
  169.   Border:=2;
  170.   GetFontOfs(6,FontOfs);
  171.   FontPtr:=Ptr(Ofs(SegC000),FontOfs);
  172.  
  173.   PixelPos:=0;
  174.   TextLen:=Length(FRunText);
  175.   Index:=0;
  176.   WorkString:=FRunText;
  177.   Setup;
  178.   Draw;
  179. end;
  180. {------------------------------------------------------------------------------}
  181.  
  182. destructor TMarquee.Destroy;
  183. begin
  184.   if FRunning then SetRunning(False);
  185.   inherited Destroy;
  186. end;
  187. {------------------------------------------------------------------------------}
  188.  
  189. procedure TMarquee.Paint;
  190. begin
  191.   Draw;
  192. end;
  193. {------------------------------------------------------------------------------}
  194.  
  195. procedure TMarquee.Clear;
  196. var
  197.   Temp: Byte;
  198. begin
  199.   Temp:=FOnColor;
  200.   FOnColor:=FOffColor;
  201.   DrawText(False);
  202.   FOnColor:=Temp;
  203. end;
  204. {------------------------------------------------------------------------------}
  205.  
  206. procedure TMarquee.Draw;
  207. var
  208.   R: TRect;
  209. begin
  210.   R:=GetClientRect;
  211.   DrawBevel(R);
  212.   Canvas.Pen.Color:=FBackGround;
  213.   Canvas.Brush.Color:=FBackGround;
  214.   InflateRect(R,-Border,-Border);
  215.   Canvas.FillRect(R);
  216.   DrawText(False);
  217. end;
  218. {------------------------------------------------------------------------------}
  219.  
  220. procedure TMarquee.DrawBevel(Rect: TRect);
  221. var
  222.   TopColor: TColor;
  223.   BottomColor: TColor;
  224.  
  225.   procedure SetColors(Bevel: TPanelBevel);
  226.   begin
  227.     TopColor:=clBtnHighlight;
  228.     if Bevel = bvLowered then TopColor:=clBtnShadow;
  229.     BottomColor:=clBtnShadow;
  230.     if Bevel = bvLowered then BottomColor:=clBtnHighlight;
  231.   end;
  232.  
  233. begin
  234.   if FBevelOuter <> bvNone then
  235.   begin
  236.     SetColors(BevelOuter);
  237.     Frame3D(Canvas,Rect,TopColor,BottomColor,BevelWidth);
  238.   end;
  239.  
  240.   if FBevelInner <> bvNone then
  241.   begin
  242.     SetColors(FBevelInner);
  243.     Frame3D(Canvas,Rect,TopColor,BottomColor,FBevelWidth);
  244.   end;
  245. end;
  246. {------------------------------------------------------------------------------}
  247.  
  248. procedure TMarquee.DrawText(Shift: Boolean);
  249. var
  250.   Pos: Byte;
  251.   I: Byte;
  252.   R: TRect;
  253. begin
  254.   R:=GetClientRect;
  255.   XPos:=R.Left + Border;
  256.   YPos:=R.Top + Border;
  257.   GetCharData(WorkString[1]);
  258.   for I:=PixelPos to 7 do PutVerticalPixels(I);
  259.  
  260.   for Pos:=2 to FCharacters do
  261.   begin
  262.     GetCharData(WorkString[Pos]);
  263.     for I:=0 to 7 do PutVerticalPixels(I);
  264.   end;
  265.  
  266.   GetCharData(WorkString[Succ(FCharacters)]);
  267.   for I:=0 to PixelPos do PutVerticalPixels(I);
  268.  
  269.   if Shift then Inc(PixelPos,FScrollBy);
  270.   if PixelPos > 7 then
  271.   begin
  272.     PixelPos:=0;
  273.     ShiftString;
  274.   end;
  275. end;
  276. {------------------------------------------------------------------------------}
  277.  
  278. procedure TMarquee.GetCharData(Character: Char); assembler;
  279. asm
  280.            push  ds
  281.            push  ds
  282.            pop   es
  283.            mov   di,offset CharArray
  284.            xor   bh,bh
  285.            mov   bl,Character
  286.            shl   bx,4
  287.            lds   si,FontPtr
  288.            add   si,bx
  289.            mov   cx,16
  290.  
  291. @MovsLoop: push  cx
  292.            lodsb
  293.            mov   ah,0
  294.            mov   cx,8
  295.  
  296. @RolLoop:  rol   al,1
  297.            adc   ah,0
  298.            ror   ah,1
  299.            loop  @RolLoop
  300.  
  301.            mov   al,ah
  302.            stosb
  303.            pop   cx
  304.            loop  @MovsLoop
  305.  
  306.            pop   ds
  307. end;
  308. {------------------------------------------------------------------------------}
  309.  
  310. procedure TMarquee.PutVerticalPixels(Horizontal: Byte);
  311. var
  312.   Vertical: Byte;
  313. begin
  314.   for Vertical:=0 to 15 do
  315.   begin
  316.     if CharArray[Vertical] and Dual[Horizontal] > 0 then
  317.       Canvas.Pixels[XPos,YPos + Vertical * FSize]:=FOnColor
  318.       else Canvas.Pixels[XPos,YPos + Vertical * FSize]:=FOffColor;
  319.   end;
  320.   Inc(XPos,FSize);
  321. end;
  322. {------------------------------------------------------------------------------}
  323.  
  324. procedure TMarquee.TimerShift(Sender: TObject);
  325. begin
  326.   DrawText(True);
  327. end;
  328. {------------------------------------------------------------------------------}
  329.  
  330. procedure TMarquee.ShiftString;
  331. begin
  332.   Inc(Index);
  333.   if FCharacters >= TextLen - Index then
  334.   begin
  335.     WorkString:=Copy(FRunText,Succ(Index),TextLen - Index);
  336.     WorkString:=WorkString + Copy(RunText,1,Succ(FCharacters) - (TextLen - Index));
  337.   end
  338.   else WorkString:=Copy(FRunText,Succ(Index),Succ(FCharacters));
  339.   if Index >= TextLen then
  340.   begin
  341.     Index:=0;
  342.     if Assigned(FOnComplete) then FOnComplete(Self);
  343.   end;
  344. end;
  345. {------------------------------------------------------------------------------}
  346.  
  347. procedure TMarquee.Setup;
  348. begin
  349.   Width:=FSize * 8 * FCharacters + 2 * Border + 1;
  350.   Height:=FSize * 16 + 2 * Border;
  351. end;
  352. {------------------------------------------------------------------------------}
  353.  
  354. procedure TMarquee.SetBackGround(Value: TColor);
  355. begin
  356.   if FBackGround <> Value then
  357.   begin
  358.     FBackGround:=Value;
  359.     Draw;
  360.   end;
  361. end;
  362. {------------------------------------------------------------------------------}
  363.  
  364. procedure TMarquee.SetBevelOuter(Value: TPanelBevel);
  365. begin
  366.   if FBevelOuter <> Value then
  367.   begin
  368.     FBevelOuter:=Value;
  369.     if FBevelOuter <> bvNone then Border:=FBevelWidth else Border:=0;
  370.     if FBevelInner <> bvNone then Inc(Border,FBevelWidth);
  371.     Setup;
  372.     Draw;
  373.   end;
  374. end;
  375. {------------------------------------------------------------------------------}
  376.  
  377. procedure TMarquee.SetBevelInner(Value: TPanelBevel);
  378. begin
  379.   if FBevelInner <> Value then
  380.   begin
  381.     FBevelInner:=Value;
  382.     if FBevelOuter <> bvNone then Border:=FBevelWidth else Border:=0;
  383.     if FBevelInner <> bvNone then Inc(Border,FBevelWidth);
  384.     Setup;
  385.     Draw;
  386.   end;
  387. end;
  388. {------------------------------------------------------------------------------}
  389.  
  390. procedure TMarquee.SetBevelWidth(Value: Byte);
  391. begin
  392.   if FBevelWidth <> Value then
  393.   begin
  394.     FBevelWidth:=Value;
  395.     if FBevelOuter <> bvNone then Border:=FBevelWidth else Border:=0;
  396.     if FBevelInner <> bvNone then Inc(Border,FBevelWidth);
  397.     Setup;
  398.     Draw;
  399.   end;
  400. end;
  401. {------------------------------------------------------------------------------}
  402.  
  403. procedure TMarquee.SetCharacters(Value: Byte);
  404. var
  405.   I: Byte;
  406. begin
  407.   if Value < 1 then Value:=1 else if Value > 80 then Value:=80;
  408.   if FCharacters <> Value then
  409.   begin
  410.     FCharacters:=Value;
  411.     if TextLen < FCharacters then
  412.     begin
  413.       for I:=TextLen to FCharacters do FRunText:=FRunText + ' ';
  414.       TextLen:=Byte(FRunText[0]);
  415.     end;
  416.     SetUp;
  417.     Draw;
  418.   end;
  419. end;
  420. {------------------------------------------------------------------------------}
  421.  
  422. procedure TMarquee.SetScrollInterval(Value: Word);
  423. begin
  424.   if FScrollInterval <> Value then
  425.   begin
  426.     FScrollInterval:=Value;
  427.     if FRunning and Assigned(Timer) then Timer.Interval:=FScrollInterval;
  428.   end;
  429. end;
  430. {------------------------------------------------------------------------------}
  431.  
  432. procedure TMarquee.SetSize(Value: Byte);
  433. begin
  434.   if Value < 1 then Value:=1 else if Value > 8 then Value:=8;
  435.   if FSize <> Value then
  436.   begin
  437.     FSize:=Value;
  438.     SetUp;
  439.     Draw;
  440.   end;
  441. end;
  442. {------------------------------------------------------------------------------}
  443.  
  444. procedure TMarquee.SetScrollBy(Value: Byte);
  445. begin
  446.   if Value < 1 then Value:=1 else if Value > 8 then Value:=8;
  447.   if FScrollBy <> Value then FScrollBy:=Value;
  448. end;
  449. {------------------------------------------------------------------------------}
  450.  
  451. procedure TMarquee.SetOffColor(Value: TColor);
  452. begin
  453.   if FOffColor <> Value then
  454.   begin
  455.     FOffColor:=Value;
  456.     Draw;
  457.   end;
  458. end;
  459. {------------------------------------------------------------------------------}
  460.  
  461. procedure TMarquee.SetOnColor(Value: TColor);
  462. begin
  463.   if FOnColor <> Value then
  464.   begin
  465.     FOnColor:=Value;
  466.     Draw;
  467.   end;
  468. end;
  469. {------------------------------------------------------------------------------}
  470.  
  471. procedure TMarquee.SetRunning(Value: Boolean);
  472. begin
  473.   if FRunning <> Value then
  474.   begin
  475.     FRunning:=Value;
  476.     if FRunning then
  477.     begin
  478.       Timer:=TTimer.Create(Self);
  479.       Timer.Interval:=FScrollInterval;
  480.       Timer.OnTimer:=TimerShift;
  481.       Timer.Enabled:=True;
  482.     end
  483.     else if Assigned(Timer) then
  484.     begin
  485.       Timer.Free;
  486.       Timer:=nil;
  487.     end;
  488.   end;
  489. end;
  490. {------------------------------------------------------------------------------}
  491.  
  492. procedure TMarquee.SetRunText(Value: string);
  493. var
  494.   I: Byte;
  495. begin
  496.   Index:=0;
  497.   FRunText:=Value;
  498.   TextLen:=Byte(FRunText[0]);
  499.   if TextLen < FCharacters then for I:=TextLen to FCharacters do FRunText:=FRunText + ' ';
  500.   TextLen:=Byte(FRunText[0]);
  501. end;
  502. {------------------------------------------------------------------------------}
  503.  
  504. procedure Register;
  505. begin
  506.   RegisterComponents('Udo|s',[TMarquee]);
  507. end;
  508. {------------------------------------------------------------------------------}
  509.  
  510. initialization
  511. end.
  512.  
  513.